Refine search
public static void main(String args[]) { float x, y, z; System.out.println("Enter two integers to calculate their sum "); Scanner in = new Scanner(System.in); x = in.nextFloat(); y = in.nextFloat(); z = sum (x,y); // this will always call sum (float x, float y) System.out.println("Sum of entered integers = "+z); }
Scanner scanner = new Scanner(input).useDelimiter(","); try { long time = scanner.nextLong(); float yaw = scanner.nextFloat(); float pitch = scanner.nextFloat(); float roll = scanner.nextFloat(); System.out.format("Angles - [%8d] Yaw: %08.3f Pitch: %08.3f Roll: %08.3f%n",time,yaw, pitch,roll); } catch (NoSuchElementException e) { // input didn't match due to insufficient elements or parsing failure }
Scanner scanner = new Scanner(System.in); System.out.println("Enter your course name: "); String courseName = scanner.nextLine(); System.out.println("Enter your course grade: "); float courseGrade = scanner.nextFloat(); System.out.println("Enter your course weight: "); float courseWeight = scanner.nextFloat(); scanner.close();
public class question3{ public static void main(String[] args){ Scanner s = new Scanner(System.in); System.out.print("Enter the first number:"); Float a = s.nextFloat(); System.out.print("Enter the second number:"); Float b = s.nextFloat(); System.out.println("Sum = " + (a+b)); System.out.println("Difference = " + (a-b)); System.out.println("Product = " + (a*b)); } }
//First you need a place to hold the value that the user inputs float radius, height; //Then you need an object that can read input from the user. Scanner sc = new Scanner(System.in); //Tell the user what you are expecting them to do System.out.println("Enter radius: "); //Now use the object to read in a value (You will need to convert it) radius = sc.nextFloat(); //Tell the user what you are expecting them to do System.out.println("Enter height: "); //Now use the object to read in a value (You will need to convert it) height = sc.nextFloat(); Cylinder cylinders = new Cylinder(radius, height); //creates the individual cylinders
import java.text.DecimalFormat; import java.util.Scanner; public class AbsoluteValue { public static void main(String[] args) { Scanner input = new Scanner(System.in); System.out.print(" Type in a number "); Float num = input.nextFloat(); if (num < 0) { num = num * -1; } System.out.println("The absolute value is " + num); input.close(); } }
int id; float grade; String name; Scanner z= new Scanner(System.in); System.out.println("Give the id:\n"); id=z.nextInt(); System.out.println("your id is :"+id+"\n"); System.out.println("Give the name:"); name=z.next(); System.out.println("your name is :"+name); System.out.println("Give the grade:\n"); grade=z.nextFloat();
import java.util.*; import java.util.Scanner; public class HandsOn14JamesVincent { public static void main(String[] args){ Scanner input = new Scanner(System.in); System.out.println("Enter a decimal number and I will round it."); float num = input.nextFloat(); float num1 = Math.round(num); float num2 = num1 - num; if (num2 <= .3) System.out.println((int)Math.ceil(num)); if (num2 > .3) System.out.println((int)Math.floor(num)); } }