Showing posts with label Output. Show all posts
Showing posts with label Output. Show all posts

Problem 1: Input and Output

Create a program that will let the user enter four numbers. If the first number is greater than the second number, and the third number is less than the fourth number, or, if the first number is greater than the second number, and the third number is less than one, display TRUE. Else, display FALSE.


import java.io.*;
public class New{
public static void main (String args[]) throws IOException
{
DataInputStream n=new DataInputStream (System.in);
int a=0;
int b=0;
int c=0;
int d=0;
System.out.println("Enter First Number: ");
a=Integer.parseInt (n.readLine());
System.out.println("Enter Second Number: ");
b=Integer.parseInt (n.readLine());
System.out.println("Enter Third Number: ");
c=Integer.parseInt (n.readLine());
System.out.println("Enter Fourth Number: ");
d=Integer.parseInt (n.readLine());
if (a>b && c<d || a >b && c<1)

System.out.println("TRUE");
else System.out.println("FALSE"); } }

Input and Output

if you want to input something in Java, you should add import java.io.*; before your class name, throws IOException after (String args[]), and DataInputStream for buffering


Try this:
import java.io.*;
public class import
{
   public static void main (String args[]) throws IOException
    {
      DataInputStream newinput = new DataInputStream(System.in);
      String new;
      System.out.println("Enter phrase here:");
      new = newinput.readLine();
      System.out.println(new);
     }
}


Note that newinput can be replaced by any word or letter which depends to the programmer. Let's say that the programmer wants to put his name on it, let's say his name is Nick, Nick can put it this way...

      DataInputStream Nick = new DataInputStream(System.in);
      String new;
      System.out.println("Enter phrase here:");
      new = Nick.readLine();
      System.out.println(new);
     }
}


Make sure also, that the uses of newinput in the program are replaced by Nick.


Notice: readLine should always be written as readLine() with an uppercased L.

Extended Search

Custom Search
Hello World