Java Tutorial
Reads three integers and identifies the biggest number.
import java.util.*; class Biggest { public static void main(String args[]) { System.out.println("Enter the values for a,b and c: "); Scanner Sc=new Scanner (System.in); int a=Sc.nextInt(); int b=Sc.nextInt(); int c=Sc.nextInt(); if(a>b&&a>c) { System.out.println("a is greater: "+a); } else if(b>a&&b>c) { System.out.println("b is greater: "+b); } else { System.out.println("c is greater: "+c); } } }Output:
D:\Java_Programs>javac Biggest.java D:\Java_Programs>java Biggest Enter the values for a,b and c: 4 8 5 b is greater: 8
Reads three integers and identifies the smallest number.
import java.util.*; class Smallest { public static void main(String args[]) { System.out.println("Enter the values for a,b and c: "); Scanner Sc=new Scanner (System.in); int a=Sc.nextInt(); int b=Sc.nextInt(); int c=Sc.nextInt(); if(a<b&&a<c) { System.out.println("a is lower: "+a); } else if(b<a&&b<c) { System.out.println("b is lower: "+b); } else { System.out.println("c is lower: "+c); } } }Output:
D:\Java_Programs>javac Biggest.java D:\Java_Programs>java Biggest Enter the values for a,b and c: 4 8 5 b is greater: 8
Java Tutorial
Privacy Policy | Copyright2020 - All Rights Reserved. | Contact us | Report website issues in Github | Facebook page | Google+ page