🔒 Closed FREE UNLIMITED Çℎḙḡḡ UNLOCKS | COMMENT LINK

Status
Not open for further replies.
1606278049638.webp
 
Pa-unlock po lods ts, Salamat po sa kabutihan at tulong mo samin :)

Solved: PT 1 Problem Solving: 1. What Will Be The Waveleng... | Çℎḙḡḡ.com
 
https://www.Çℎḙḡḡ.com/homework-help...ter-20-problem-23e-solution-9780133975888-exc

eto po sana salamat po
 
Java Program:

/* Java Application that reads a value from user and tries to convert and print numeric value and if conversion fails, handles the error appropriately and prints appropriate error message */

import java.util.*;

class TryToParseString
{
//Main method
public static void main(String args[])
{
String input;
int value;

Scanner sc = new Scanner(System.in);

try
{
//Reading a value from user
System.out.print("\n Enter an integer value: ");
input = sc.nextLine();

//Trying to parse the input to integer
value = Integer.parseInt(input);

//If conversion success, prints the converted integer value
System.out.println("\n\n Integer Value: " + value);
}
catch(NumberFormatException ex)
{
//If conversion fails, prints appropriate message to console
System.out.println("\n\n Error: Non-Numeric Value entered.... \n");
}
}
}

--------------------------------------------------------------------------------------------------------------------------------------------------------------------

Sample Output:

C:Windows system321cmd.exe FJava javac TryToParseString-java F:\Java>java TryToParseString Enter an integer value: 23 Integer
 
public class Book

{

String bookTitle;

int numPages;



private void setBTitle(String title)

{

bookTitle = title;

}



private void setBPages(int pages)

{

numPages = pages;

}



private String getBTitle()

{

return bookTitle;

}



private int getBPages()

{

return numPages;

}



public void displayBookInfo()

{

System.out.println("The book's title is: " + bookTitle + ".");

System.out.println("The number of pages is: " + numPages + ".");

}

}

Here is my code for Texbook.java:



public class Textbook extends Book

{

int gradeLevel;



public int getGLevel()

{

return gradeLevel;

}



public void setGLevel(int level)

{

gradeLevel = level;

}

}
 
Status
Not open for further replies.

About this Thread

  • 313
    Replies
  • 2K
    Views
  • 84
    Participants
Last reply from:
E J I E L

Trending Topics

Online now

Members online
1,158
Guests online
1,452
Total visitors
2,610

Forum statistics

Threads
2,287,030
Posts
29,041,896
Members
1,216,347
Latest member
Humdeedum
Back
Top